home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / RestoreGuest / rg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-16  |  3.7 KB  |  118 lines

  1. /*
  2. -------------------------------------------------------------------------
  3. rg.c  --  A program to restore a guest account after use.
  4. -------------------------------------------------------------------------
  5. version 1.0
  6. by Eric Celeste <efc@mit.edu>
  7. -------------------------------------------------------------------------
  8. This is a small program designed to be used as a LogoutHook on a
  9. user group machine. We like letting folks use the NeXT in the
  10. resource center, but find that they often trash the guest account
  11. and the next person to log in finds a tremendous mess. This program
  12. runs every time someone logs out of the machine and ensures that
  13. the guest account is set back to the state it was found in. It does
  14. this by recreating the guest account from a template account every
  15. time a user logs out of the machine. To make changes to the guest
  16. account permanently, you simply log into the template account and
  17. make the changes.
  18.  
  19. To use this program:
  20.  
  21. (1) Make sure you have both a guest account and a template account
  22.     set up on your machine. If you don't know how to create these
  23.     accounts, then you should probably not be trying to use this 
  24.     program!
  25.  
  26. (2) Change the defines to meet the conditions of your environment
  27.     and recompile this code.
  28.     (a) Change the defines.
  29.     (b) Save this file.
  30.     (c) Open a terminal window.
  31.     (d) Change directory "cd" to the directory with this file in it.
  32.     (e) Compile this file "cc rg.c -o rg".
  33.  
  34. (3) Strip the executable file: "strip rg".
  35.  
  36. (4) Make sure you are root by "su" or loging into the root account.
  37.  
  38. (5) Copy this file to /usr/local/bin so everyone knows where to
  39.     find it: "cp rg /usr/local/bin/rg".
  40.  
  41. (6) Change the file modes so that only root can execute it:
  42.     "chmod 700 /usr/local/bin/rg".
  43.  
  44. (7) Add a line to the defaults database that will execute this
  45.     command every time a user logs out of an account:
  46.     "dwrite loginwindow LogoutHook /usr/local/bin/rg".
  47.  
  48. (8)    Reboot the machine so that the new loginwindow default is used.
  49.  
  50. This does slow down logging out a bit, but for a machine in a public
  51. place, that price is well worth it.
  52.  
  53. By the way, this program can be run from the Terminal window by
  54. root for debugging purposes. It is probably a good idea to do this
  55. before installing it as the LogoutHook, just to make sure it does
  56. what you expect!
  57. -------------------------------------------------------------------------
  58. */
  59.  
  60. #import <stdio.h>
  61. #import <stdlib.h>
  62.  
  63. #define GUEST_ACCOUNT_NAME            "guest"
  64. #define GUEST_ACCOUNT_DIRECTORY        "/Users"
  65. #define GUEST_ACCOUNT_OWNER            "guest.other"
  66. #define TEMPLATE_ACCOUNT_NAME        "guesttemplate"
  67. #define TEMPLATE_ACCOUNT_DIRECTORY    "/usr/local"
  68.  
  69. void main(int argc, char *argv[]) {
  70.  
  71.     char command[200];
  72.     
  73.     sprintf(command,"/bin/cp -r %s/%s %s",
  74.         TEMPLATE_ACCOUNT_DIRECTORY,
  75.         TEMPLATE_ACCOUNT_NAME,
  76.         GUEST_ACCOUNT_DIRECTORY
  77.     );
  78.     if (system(command)) {
  79.         printf("rg: error while copying template account\n");
  80.         exit(1);
  81.     } else {
  82.         sprintf(command,"/bin/rm -r %s/%s",
  83.             GUEST_ACCOUNT_DIRECTORY,
  84.             GUEST_ACCOUNT_NAME
  85.         );
  86.         if (system(command)) {
  87.             printf("rg: error while removing dirty guest account\n");
  88.             exit(1);
  89.         } else {
  90.             sprintf(command,"/bin/mv %s/%s %s/%s",
  91.                 GUEST_ACCOUNT_DIRECTORY,
  92.                 TEMPLATE_ACCOUNT_NAME,
  93.                 GUEST_ACCOUNT_DIRECTORY,
  94.                 GUEST_ACCOUNT_NAME
  95.             );
  96.             if (system(command)) {
  97.                 printf("rg: error while moving template to guest account\n");
  98.                 exit(1);
  99.             } else {
  100.                 sprintf(command,"/usr/etc/chown -f -R %s %s/%s",
  101.                     GUEST_ACCOUNT_OWNER,
  102.                     GUEST_ACCOUNT_DIRECTORY,
  103.                     GUEST_ACCOUNT_NAME
  104.                 );
  105.                 if (system(command)) {
  106.                     printf("rg: error while change guest account ownership\n");
  107.                     exit(1);
  108.                 } else {
  109.                     // no error reported
  110.                     exit(0);
  111.                 }
  112.             }
  113.         }
  114.     }
  115.     
  116.     printf("rg: unknown error\n");
  117.     exit(1);    
  118. }